<template>
  <n-form
    :model="formData"
    :rules="formRules"
    ref="formInstance"
    label-placement="left"
    :label-width="SlashAppContext.getCoefficient()*80 + 'px'">
    <n-grid x-gap="12" :cols="2" responsive="self">
            <n-gi >
        <n-form-item label="登录名" path="loginName">
          <n-input v-model:value="formData.loginName" placeholder="请输入登录名" />
        </n-form-item>
      </n-gi>
            <n-gi >
        <n-form-item label="登录ip" path="loginIp">
          <n-input v-model:value="formData.loginIp" placeholder="请输入登录ip" />
        </n-form-item>
      </n-gi>
            <n-gi >
        <n-form-item label="登录消息" path="loginMsg">
          <n-input v-model:value="formData.loginMsg" placeholder="请输入登录消息" />
        </n-form-item>
      </n-gi>
            <n-gi >
        <n-form-item label="用户编号" path="fkUserId">
          <n-input v-model:value="formData.fkUserId" placeholder="请输入用户编号" />
        </n-form-item>
      </n-gi>
            <n-gi >
        <n-form-item label="浏览器" path="loginBrowser">
          <n-input v-model:value="formData.loginBrowser" placeholder="请输入浏览器" />
        </n-form-item>
      </n-gi>
            <n-gi >
        <n-form-item label="操作系统" path="loginOs">
          <n-input v-model:value="formData.loginOs" placeholder="请输入操作系统" />
        </n-form-item>
      </n-gi>
            <n-gi >
        <n-form-item label="登录来源" path="loginSource">
          <n-input v-model:value="formData.loginSource" placeholder="请输入登录来源" />
        </n-form-item>
      </n-gi>
            <n-gi >
        <n-form-item label="登出时间" path="loginOutTime">
          <n-input v-model:value="formData.loginOutTime" placeholder="请输入登出时间" />
        </n-form-item>
      </n-gi>
            <n-gi >
        <n-form-item label="分钟" path="loginDuration">
          <n-input v-model:value="formData.loginDuration" placeholder="请输入分钟" />
        </n-form-item>
      </n-gi>
            <n-gi >
        <n-form-item label="登录时sesstion" path="sessionKey">
          <n-input v-model:value="formData.sessionKey" placeholder="请输入登录时sesstion" />
        </n-form-item>
      </n-gi>
          </n-grid>
  </n-form>
</template>
<script lang="ts">
import { onMounted, ref } from "vue";
import { enabledOptions, formRules } from "./Service";
import httpApi from "./httpApi";
import { FormInst } from "naive-ui";
import { SlashAppContext, checkFormData } from "slash-admin";

export default {
  props: {
    id: {
      type: [String, Number],
      default: null
    },
    readMode: {
      type: [String],
      default: "read"
    }
  },
  setup: function(props) {
    const formInstance = ref<FormInst | null>(null);
    const formData = ref<any>({
      id: props.id,
      enabled: 1
    });
    const init = async () => {
      if (props.id) {
        let msg = await httpApi.selectById(props.id);
        formData.value = msg.data;
      }
    };
    const doSubmit = async () => {
      await checkFormData(formInstance);
      return httpApi.doSaveEntity(formData.value);
    };
    const doUpdate = async () => {
      await checkFormData(formInstance);
      return httpApi.doUpdateEntity(formData.value);
    };
    onMounted(() => {
      init();
    });
    return {
      enabledOptions,
      formData,
      formInstance,
      formRules,
      doSubmit,
      doUpdate,
      SlashAppContext
    };
  }
};
</script>

<style lang="less" scoped></style>
